package gov.ccswj.modules.bdbusiness.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import gov.ccswj.common.utils.PageUtils;
import gov.ccswj.common.utils.Query;
import gov.ccswj.common.utils.R;
import gov.ccswj.modules.bdbusiness.entity.ACcdataEntity;
import gov.ccswj.modules.bdbusiness.entity.AIndustyGasEntity;
import gov.ccswj.modules.bdbusiness.service.AIndustyGasService;




/**
 * 
 * 
 * @author ZhangYx
 * @email ********@gmail.com
 * @date 2017-11-30 15:29:30
 */
@RestController
@RequestMapping("/bdbusiness/aindustygas")
public class AIndustyGasController {
	@Autowired
	private AIndustyGasService aIndustyGasService;
	
	
	/**
	 *getDoubleReturnNum 
	 */
	@RequestMapping("/gasnum")
	public R getDoubleReturnNum(@RequestParam  Double ns,Double we,Double param){
		
		///List<AIndustyGasEntity> aIndustyGasList = aIndustyGasService.queryList(query);
		List<AIndustyGasEntity> gass = aIndustyGasService.getGasNum(ns,we,param);
		
		List<ACcdataEntity> ccdata = aIndustyGasService.getData(ns,we,param);
		Double sumperson=0.00;
		Double sumcar=0.00;
		if(ccdata!=null||ccdata.size() !=0 ){
			for(ACcdataEntity c:ccdata){
				sumperson=sumperson+c.getPerson_num();
				sumcar=sumcar+c.getCar_num();
			}
		}
		
		
		Map<Object,Object> map= new HashMap<>();
		map.put("gasnumber", gass.size());
		map.put("gas", gass);
		//map.put("ccdata", ccdata);
		map.put("carsum", sumcar.intValue());
		map.put("peronsum", sumperson.intValue());
		return R.ok().put("data", map);
	}
	
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("bdbusiness:aindustygas:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<AIndustyGasEntity> aIndustyGasList = aIndustyGasService.queryList(query);
		int total = aIndustyGasService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(aIndustyGasList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("bdbusiness:aindustygas:info")
	public R info(@PathVariable("id") Integer id){
		AIndustyGasEntity aIndustyGas = aIndustyGasService.queryObject(id);
		
		return R.ok().put("aIndustyGas", aIndustyGas);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("bdbusiness:aindustygas:save")
	public R save(@RequestBody AIndustyGasEntity aIndustyGas){
		aIndustyGasService.save(aIndustyGas);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("bdbusiness:aindustygas:update")
	public R update(@RequestBody AIndustyGasEntity aIndustyGas){
		aIndustyGasService.update(aIndustyGas);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("bdbusiness:aindustygas:delete")
	public R delete(@RequestBody Integer[] ids){
		aIndustyGasService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
